home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / dlg / support.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-14  |  3.6 KB  |  183 lines  |  [TEXT/MPS ]

  1. /*
  2.  * SOFTWARE RIGHTS
  3.  *
  4.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  5.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  6.  * company may do whatever they wish with source code distributed with
  7.  * PCCTS or the code generated by PCCTS, including the incorporation of
  8.  * PCCTS, or its output, into commerical software.
  9.  * 
  10.  * We encourage users to develop software with PCCTS.  However, we do ask
  11.  * that credit is given to us for developing PCCTS.  By "credit",
  12.  * we mean that if you incorporate our source code into one of your
  13.  * programs (commercial product, research project, or otherwise) that you
  14.  * acknowledge this fact somewhere in the documentation, research report,
  15.  * etc...  If you like PCCTS and have developed a nice tool with the
  16.  * output, please mention that you developed it using PCCTS.  In
  17.  * addition, we ask that this header remain intact in our source code.
  18.  * As long as these guidelines are kept, we expect to continue enhancing
  19.  * this system and expect to make other tools available as they are
  20.  * completed.
  21.  *
  22.  * DLG 1.23
  23.  * Will Cohen
  24.  * With mods by Terence Parr; AHPCRC, University of Minnesota
  25.  * 1989-1994
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include "dlg.h"
  30. #ifdef MEMCHK
  31. #include "trax.h"
  32. #else
  33. #ifdef __STDC__
  34. #include <stdlib.h>
  35. #else
  36. #include <malloc.h>
  37. #endif /* __STDC__ */
  38. #endif
  39.  
  40. int    err_found = 0;            /* indicates whether problem found */
  41.  
  42. internal_error(s,file,line)
  43. char *s,*file;
  44. int line;
  45. {
  46.     fprintf(stderr,s,file,line);
  47.     exit(1);
  48. }
  49.  
  50. char *dlg_malloc(bytes,file,line)
  51. int bytes;
  52. char *file;
  53. int line;
  54. {
  55.     char *t;
  56.  
  57.     t = (char *) malloc(bytes);
  58.     if (!t){
  59.         /* error */
  60.         internal_error("%s(%d): unable to allocate memory\n",
  61.             file,line);
  62.     }
  63.     return t;
  64. }
  65.  
  66.  
  67. char *dlg_calloc(n,bytes,file,line)
  68. int n,bytes;
  69. char *file;
  70. int line;
  71. {
  72.     char *t;
  73.  
  74.     t = (char *) calloc(n,bytes);
  75.     if (!t){
  76.         /* error */
  77.         internal_error("%s(%d): unable to allocate memory\n",
  78.             file,line);
  79.     }
  80.     return t;
  81. }
  82.  
  83.  
  84. FILE *read_stream(name)
  85. char *name;
  86. {
  87.     FILE *f;
  88.  
  89.     if (name){
  90.         if (name[0] == '-') {
  91.             fprintf(stderr, "dlg: invalid option: '%s'\n", name);
  92.             f = NULL;
  93.         }else{
  94.             f = fopen(name, "r");
  95.             if (f == NULL){
  96.                 /* couldn't open file */
  97.                 fprintf(stderr,
  98.                     "dlg: Warning: Can't read file %s.\n",
  99.                     name);
  100.             }
  101.         }
  102.     }else{
  103.         /* open stdin if nothing there */
  104.         f = stdin;
  105.     }
  106.     return f;
  107. }
  108.  
  109. FILE *write_stream(name)
  110. char *name;
  111. {
  112.     FILE *f;
  113.  
  114.     if (name){
  115.         if (name[0] == '-') {
  116.             fprintf(stderr, "dlg: invalid option: '%s'\n", name);
  117.             f = NULL;
  118.         }else{
  119.             f = fopen(OutMetaName(name), "w");
  120.             if (f == NULL){
  121.                 /* couldn't open file */
  122.                 fprintf(stderr,
  123.                     "dlg: Warning: Can't write to file %s.\n",
  124.                     name);
  125.             }
  126.             else
  127.                 special_fopen_actions(OutMetaName(name));
  128.         }
  129.     }else{
  130.         /* open stdout if nothing there */
  131.         f = stdout;
  132.     }
  133.     return f;
  134. }
  135.  
  136.  
  137. void fatal(message,line_no)
  138. char *message;
  139. int line_no;
  140. {
  141.     fprintf(stderr,ErrHdr,
  142.         (file_str[0] ? file_str[0] : "stdin"), line_no);
  143.     fprintf(stderr, " Fatal: %s\n", message);
  144.     exit(2);
  145. }
  146.  
  147. void error(message,line_no)
  148. char *message;
  149. int line_no;
  150. {
  151.     fprintf(stderr,ErrHdr,
  152.         (file_str[0] ? file_str[0] : "stdin"), line_no);
  153.     fprintf(stderr, " Error: %s\n", message);
  154.     err_found = 1;
  155. }
  156.  
  157. void warning(message,line_no)
  158. char *message;
  159. int line_no;
  160. {
  161.     fprintf(stderr,ErrHdr,
  162.         (file_str[0] ? file_str[0] : "stdin"), line_no);
  163.     fprintf(stderr, " Warning: %s\n", message);
  164. }
  165.  
  166. char *
  167. #ifdef __STDC__
  168. OutMetaName(char *n)
  169. #else
  170. OutMetaName(n)
  171. char *n;
  172. #endif
  173. {
  174.     static char buf[200+1];
  175.  
  176.     if ( strcmp(outdir,TopDirectory)==0 ) return n;
  177.     strcpy(buf, outdir);
  178.     if ( strcmp(&buf[strlen(buf) - 1], DirectorySymbol ) )
  179.         strcat(buf, DirectorySymbol);
  180.     strcat(buf, n);
  181.     return buf;
  182. }
  183.